<?php
class Zendvn_File_Upload extends Zend_File_Transfer_Adapter_Http{
	
	public function upload($fileName,$uploadDir,$options = null,$prefix = 'pic_'){
		
		$this->setDestination($uploadDir);
		if($options == null){
			$this->receive($fileName);
			$newFileName = $this->getFileName($fileName,false);
		}
		if($options['task'] == 'rename' ){
			$info = $this->getFileName($fileName);
			preg_match('#\.([^\.]+)$#',$info,$matches);
			$fileExtension  = $matches[1];
			$newFileName 	= $prefix .'.'. $fileExtension;
		
			$options = array('target' => $uploadDir . '/' . $newFileName,'overwrite'=>true);
			$this->addFilter('Rename',$options,$fileName);
			$this->receive($fileName);
		}
		
		return $newFileName;
	}
	public function removeFile($filename,$dir_filename){
		$fileUpload =	$dir_filename.$filename;	
		@unlink($fileUpload);
	}
}